<template>
  <el-dialog v-model="show" :title="title" width="500px" append-to-body :close-on-click-modal="false">
    <el-form ref="dialogRef" label-width="100px">
      <el-form-item label="下载模板">
        <el-link href="/file/sportsmanTemplate.xlsx" type="primary" target="_blank">人员模板</el-link>
      </el-form-item>

      <el-form-item label="上传模板" prop="discount">
        <fileUpload ref="upload" name="excel" :action="action" :accept="accept" @uploadSuccess="uploadSuccess"/>
      </el-form-item>
    </el-form>


  </el-dialog>
</template>

<script setup>
import { getCurrentInstance } from '@vue/runtime-core'
import { reactive, ref, watch } from 'vue'
import { toRefs } from '@vueuse/shared'
import * as match from '@/api/match/pc'
import { ElMessage, ElMessageBox } from 'element-plus'

const { proxy } = getCurrentInstance()

const emit = defineEmits(['submitForm'])

const action = ref('')
const accept = ref('.xlsx')
const title = ref('')
const show = ref(false)

function uploadSuccess(res) {
  console.log(res)
  cancel()
  if (res.code == 500) {
    ElMessageBox.alert(res.data, '提示', {
      confirmButtonText: '好的'
    })
  } else {
    proxy.$modal.msgSuccess(`${res.msg}`)
  }

  emit('uploadSuccess')
  proxy.$refs['upload'].handleClear()
}

const open = (params) => {
  show.value = true
  title.value = params.title
  action.value = `/systemj/personInfo/importPerson/${params.groupId}`
}
defineExpose({
  open
})

function cancel() {
  show.value = false
}
</script>

<style scoped>
:deep(.el-upload__tip) {
  display: none
}
</style>
